/*
 * @Description: 添加计划
 * @Author: Zzt
 * @Date: 2022-08-09 14:59:01
 * @LastEditTime: 2022-08-11 17:58:40
 */

import { FC } from 'react';
import { Button, Form, Modal, Tabs } from 'antd';
import { ICommonDialog } from '@/interfaces/global';
import PlanRecord from './common/PlanRecord';
import Executive from './common/Executive';
import { useAppraisalAndDispositionContext } from '../../contexts/AppraisalAndDispositionContext';

const { TabPane } = Tabs;

interface AddPlanProps extends ICommonDialog {
  data: any;
}
const AddPlan: FC<AddPlanProps> = (props) => {
  const { addPlan } = useAppraisalAndDispositionContext();
  const [form] = Form.useForm();
  const { visible, data, onClose } = props;

  const handleOk = () => {
    form.submit();
  };
  const handleCancel = () => {
    onClose();
  };
  const onFinish = (values: any) => {
    form.resetFields();
    console.log(values);
    addPlan(values);
    onClose();
  };
  return (
    <div>
      <Modal
        title="计划与执行记录"
        visible={visible}
        onOk={handleOk}
        onCancel={handleCancel}
        footer={[
          <Button key="back" onClick={handleCancel}>
            取消
          </Button>,
          <Button key="submit" type="primary" onClick={handleOk}>
            保存
          </Button>
        ]}
      >
        <Tabs defaultActiveKey="1">
          <TabPane tab="计划记录" key="1">
            <Form
              form={form}
              labelCol={{ span: 5 }}
              wrapperCol={{ span: 20 }}
              onFinish={onFinish}
              initialValues={data}
            >
              <PlanRecord form={form} />
            </Form>
          </TabPane>
          <TabPane tab="执行计划" key="2">
            <Form
              form={form}
              labelCol={{ span: 5 }}
              wrapperCol={{ span: 20 }}
              onFinish={onFinish}
              initialValues={data}
            >
              <Executive form={form} />
            </Form>
          </TabPane>
        </Tabs>
      </Modal>
    </div>
  );
};
export default AddPlan;
